<?php
namespace app\service;
use think\Db;
class repairService{
    //-----------------------------------------------------发布公告---------------------------------------------------------
    //查询所有公告
    public function noticeList($where,$page){
        return Db::name('notice')->where($where)->order('id desc')->paginate(100, false, [
            'page'  =>  $page,
            'query' =>  $where
        ]);
    }
    //查询条数
    public function noticeNumber($where){
        return Db::name('notice')->where($where)->select();
    }
    //查询小区名称
    public function communityIdName($community_id){
        return Db::name('community')->where('community_id',$community_id)->value('community_name');
    }
    //查询所有小区
    public function communityList($where){
        return Db::name('community')->where($where)->order('id asc')->select();
    }
    //公告添加
    public function noticeAdd($data){
        return Db::name('notice')->insert($data);
    }
    //小区公告
    public function noticeInfoList($community_id){
        return Db::name('notice')->where('community_id',$community_id)->order('id desc')->select();
    }
    //-----------------------------------------------------投诉建议---------------------------------------------------------
    //投诉建议查询
    //多条件查询
    public function proposalList($where,$page){
        return Db::name('proposal')->where($where)->order('id desc')->paginate(100, false, [
            'page'  =>  $page,
            'query' =>  $where
        ]);
    }
    //查询条数
    public function proposalNumber($where){
        return Db::name('proposal')->where($where)->select();
    }
    //投诉建议添加
    public function proposalAdd($data){
        return Db::name('proposal')->insertGetId($data);
    }
    //查询新添加信息
    public function proposalIdList($id){
        return Db::name('proposal')->where('id',$id)->find();
    }
    //查询小区信息
    public function communityIdInfo($id){
        return Db::name('community')->where('id',$id)->find();
    }
    //---------------------------------------------------报事报修类型-------------------------------------------------------
    //报事报修类型查询
    public function typeList(){
        return Db::name('repair_type')->order('id asc')->select();
    }
    //报事报修查询名称是否重复
    public function typeName($name){
        return Db::name('repair_type')->where('name',$name)->find();
    }
    public function typeAdd($data){
        return Db::name('repair_type')->insert($data);
    }
    public function typeId($id){
        return Db::name('repair_type')->where('id',$id)->find();
    }
    public function typeDel($id){
        return Db::name('repair_type')->delete($id);
    }
    //-----------------------------------------------------报事报修---------------------------------------------------------
    //多条件查询
    public function repairList($where,$page){
        return Db::name('repair')->where($where)->order('id desc')->paginate(100, false, [
            'page'  =>  $page,
            'query' =>  $where
        ]);
    }
    //查询条数
    public function repairNumber($where){
        return Db::name('repair')->where($where)->select();
    }
    //添加报事报修
    public function repairAdd($data){
        return Db::name('repair')->insertGetId($data);
    }
    //查询指定ID数据
    public function repairIdList($id){
        return Db::name('repair')->where('id',$id)->find();
    }
    //查询报修类型
    public function typeIdName($id){
        return Db::name('repair_type')->where('id',$id)->value('name');
    }
    //解决报事报修
    public function repairIdSolve($data){
        return Db::name('repair')->update($data);
    }
    //查询房号
    public function roomAddress($community_id,$address){
        return Db::name('roominfo')->where('community_id',$community_id)->where('address',$address)->find();
    }
}